package com.guoguo.service.impl;

import com.github.pagehelper.PageHelper;
import com.guoguo.base.PageBean;
import com.guoguo.entity.Role;
import com.guoguo.mapper.RoleMapper;
import com.guoguo.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by KLSD on 2017/9/13.
 */
@Service
public class RoleServiceImpl implements RoleService {
    @Autowired
    private RoleMapper roleMapper;

    @Override
    public PageBean<Role> selectRoleList(int pageNumber,int pageSize) {
        PageHelper.startPage(pageNumber,pageSize);
        List<Role> role=roleMapper.selectRoleList();
        return new PageBean<Role>(role);
    }

    @Override
    public Role selectByPrimaryKey(String roleId) {
        return roleMapper.selectByPrimaryKey(roleId);
    }

    @Override
    public Role addRole(String roleId, String roleName, String roleDescription) {
        //添加修改
        Role role = roleMapper.selectByPrimaryKey(roleId);
        if (role == null) {
            role = new Role(roleId, roleName, roleDescription);
            return roleMapper.insertSelective(role);
        } else {
            role.setRoleId(roleId);
            role.setRoleName(roleName);
            role.setRoleDescription(roleDescription);
            return roleMapper.updateByPrimaryKeySelective(role);
        }

    }

    @Override
    public int deleteByPrimaryKey(String roleId) {
        return roleMapper.deleteByPrimaryKey(roleId);
    }
}
